package org.classg.edu.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.classg.edu.entity.Video;
import org.classg.edu.service.VideoService;
import org.classg.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-05-18
 */
@Api(description = "小节管理")
@RestController
@RequestMapping("/eduservice/video")
@CrossOrigin
public class VideoController {

    @Autowired
    private VideoService videoService;

    @ApiOperation(value = "新增小节")
    @PostMapping("/insertVideo")
    public R insertVideo(@ApiParam(name = "video", value = "小节对象", required = true) @RequestBody Video video) {
        videoService.save(video);
        return R.ok();
    }

    @ApiOperation(value = "根据小节id查询小节")
    @GetMapping("/queryVideoById/{id}")
    public R queryVideoById(@ApiParam(name = "id", value = "小节id", required = true) @PathVariable String id) {
        Video video = videoService.getById(id);
        return R.ok().data("video", video);
    }

    @ApiOperation(value = "更新小节")
    @PutMapping("/updateVideo")
    public R updateVideo(@ApiParam(name = "video", value = "小节对象", required = true) @RequestBody Video video) {
        videoService.updateById(video);
        return R.ok();
    }


    @ApiOperation(value = "根据小节id删除小节")
    @DeleteMapping("/deleteVideoById/{id}")
    public R deleteVideoById(@PathVariable String id) {
        videoService.deleteVideoById(id);
        return R.ok();
    }
}

